package com.pzc.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.pzc.entity.admin;
import com.pzc.service.AdminService;

/**
 * Servlet implementation class DoAdminLogin
 */
@WebServlet("/DoAdminLogin")
public class DoAdminLogin extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DoAdminLogin() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		String error="";
		String adminname = request.getParameter("adminname");
		String adminpassword = request.getParameter("adminpassword");
		admin a = new admin();
		a.setAdminname(adminname);
		a.setAdminpassword(adminpassword);
		
		AdminService as = new AdminService();
		if(as.login(adminname,adminpassword)){
			HttpSession session = request.getSession();
			session.setAttribute(adminname, "adminname");
			System.out.println("管理员登录成功！");
			request.setAttribute(adminname, a.getAdminname());
			request.getRequestDispatcher("ToAdministratorCenter").forward(request, response);
		}else{
			System.out.println("密码错误!");
			error="错误密码";
			request.setAttribute(error, "error");
			request.getRequestDispatcher("ToAdministratorLogin").forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
	}

}
